package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.HmzProduct;
import com.ruoyi.system.service.IHmzProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HmzRkInfoMapper;
import com.ruoyi.system.domain.HmzRkInfo;
import com.ruoyi.system.service.IHmzRkInfoService;

/**
 * 通道们入库记录Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-17
 */
@Service
public class HmzRkInfoServiceImpl implements IHmzRkInfoService {
    @Autowired
    private HmzRkInfoMapper hmzRkInfoMapper;
    @Autowired
    private IHmzProductService hmzProductService;

    /**
     * 查询通道们入库记录
     *
     * @param id 通道们入库记录主键
     * @return 通道们入库记录
     */
    @Override
    public HmzRkInfo selectHmzRkInfoById(Long id) {
        return hmzRkInfoMapper.selectHmzRkInfoById(id);
    }

    /**
     * 查询通道们入库记录列表
     *
     * @param hmzRkInfo 通道们入库记录
     * @return 通道们入库记录
     */
    @Override
    public List<HmzRkInfo> selectHmzRkInfoList(HmzRkInfo hmzRkInfo) {
        List<HmzRkInfo> hmzRkInfos = hmzRkInfoMapper.selectHmzRkInfoList(hmzRkInfo);
        if (hmzRkInfos != null && hmzRkInfos.size() > 0) {
            for (HmzRkInfo rkInfo : hmzRkInfos) {
                Long productId = rkInfo.getProductId();
                HmzProduct hmzProduct = hmzProductService.selectHmzProductById(productId);
                if (StringUtils.isNotNull(hmzProduct)) {
                    rkInfo.setProduct(hmzProduct);
                }

            }
        }
        return hmzRkInfos;
    }

    /**
     * 新增通道们入库记录
     *
     * @param hmzRkInfo 通道们入库记录
     * @return 结果
     */
    @Override
    public int insertHmzRkInfo(HmzRkInfo hmzRkInfo) {
        hmzRkInfo.setCreateTime(DateUtils.getNowDate());
        return hmzRkInfoMapper.insertHmzRkInfo(hmzRkInfo);
    }

    /**
     * 修改通道们入库记录
     *
     * @param hmzRkInfo 通道们入库记录
     * @return 结果
     */
    @Override
    public int updateHmzRkInfo(HmzRkInfo hmzRkInfo) {
        hmzRkInfo.setUpdateTime(DateUtils.getNowDate());
        return hmzRkInfoMapper.updateHmzRkInfo(hmzRkInfo);
    }

    /**
     * 批量删除通道们入库记录
     *
     * @param ids 需要删除的通道们入库记录主键
     * @return 结果
     */
    @Override
    public int deleteHmzRkInfoByIds(Long[] ids) {
        return hmzRkInfoMapper.deleteHmzRkInfoByIds(ids);
    }

    /**
     * 删除通道们入库记录信息
     *
     * @param id 通道们入库记录主键
     * @return 结果
     */
    @Override
    public int deleteHmzRkInfoById(Long id) {
        return hmzRkInfoMapper.deleteHmzRkInfoById(id);
    }
}
